package com.example.eci_quartz.cloudcc.dao;



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Locale;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

public class DefaultConnectionFactory implements ConnectionFactory {

	// 获取配置文件内容
		ResourceBundle bundle = PropertyResourceBundle.getBundle("config");
		//驱动名称
	    private String DRIVER_NAME =bundle.getString("DRIVER_NAME");
		//URl
		private String URL = bundle.getString("URL");//数据库名称
		//链接用户名
		private String USERNAME =bundle.getString("USERNAME");
		//链接密码
		private String PASSWORD =bundle.getString("PASSWORD");

		/**
		 * 获得数据库链接对象
		 *
		 * @return数据库链接对象
		 */
		@Override
		public Connection getConnection() {
			Connection conn = null;
			//.println(DRIVER_NAME+"---"+URL+"==="+USERNAME+"---"+PASSWORD);
			try {
				Class.forName(DRIVER_NAME);
				conn = DriverManager.getConnection(URL,USERNAME, PASSWORD);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return conn;
		}

	public static void main(String[] args) {
		ResourceBundle bundle = PropertyResourceBundle.getBundle("config",new Locale("zh","CN"));
		String DRIVER_NAME =bundle.getString("DRIVER_NAME");
	}

}
